package bravo.xc.com.xc_bravo_android.operation.withdraw.withdrawrecord;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import bravo.xc.com.xc_bravo_android.R;
import bravo.xc.com.xc_bravo_android.adapter.WithDrawAdapter;
import bravo.xc.com.xc_bravo_android.base.BaseMVPActivity;
import bravo.xc.com.xc_bravo_android.beans.WithDrawRecordBeans;
import bravo.xc.com.xc_bravo_android.beans.WithdrawRecordResultBeans;
import bravo.xc.com.xc_bravo_android.operation.person_center.PersonalCenterActivity;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class WithdrawRecordActivity extends BaseMVPActivity<WithdrawRecordContract.WithdrawRecordView,WithdrawRecordContract.WithdrawRecordPresenter> implements View.OnClickListener,WithdrawRecordContract.WithdrawRecordView{

    private LinearLayout layout_title_left;
    private TextView tv_title_meg;
    private ListView record;
    private WithDrawAdapter withDrawAdapter;
    private WithDrawRecordBeans withDrawRecordBeans;

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_title_left:
                Intent intent = new Intent(this, PersonalCenterActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }

    @Override
    public void showToast(String str) {
        Toast.makeText(WithdrawRecordActivity.this,str,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected WithdrawRecordContract.WithdrawRecordPresenter createPresnter() {
        return new WithdrawRecordPresenter();
    }

    @Override
    protected void initView() {
        layout_title_left=(LinearLayout)findViewById(R.id.layout_title_left);
        layout_title_left.setOnClickListener(this);
        tv_title_meg=(TextView)findViewById(R.id.tv_title_msg);
        tv_title_meg.setText("提现记录");
        record = (ListView) findViewById(R.id.lv_withdraw_record);

        record.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //添加点击事件
            }
        });

    }

    @Override
    protected void initData() {
        withDrawRecordBeans = new WithDrawRecordBeans();
        withDrawRecordBeans.setPageNum("");
        withDrawRecordBeans.setUserId(String.valueOf(getSharedPreferences("UserInfo",MODE_PRIVATE).getInt("userId",0)));
        presenter.doRecord(withDrawRecordBeans);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_withdraw_record;
    }

    @Override
    protected Unbinder getBinder() {
        return ButterKnife.bind(WithdrawRecordActivity.this);
    }

    @Override
    protected void onChildDestroy() {
        presenter.onDetached();
    }

    @Override
    public void setAdapter(WithdrawRecordResultBeans withdrawRecordResultBeans) {
        withDrawAdapter = new WithDrawAdapter(this,R.layout.item_withdraw_record,withdrawRecordResultBeans.getData());
        record.setAdapter(withDrawAdapter);
    }
}
